<?php
require '../conn.php';
require 'config.php';
require '../inc/function.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../css/admin.css" type="text/css" />
<script type="text/javascript" src="inc/function.js"></script>
</head>
<body>
<?php
$k_order=ReStra($_POST['k_order']);
$k_name=ReStra($_POST['k_name']);
$k_url=ReStra($_POST['k_url']);

switch($act){
case 'add';
	$sql="insert into ".$language."_keys(k_order,k_name,k_url) values($k_order,'$k_name','$k_url')";
	mysql_query($sql) or die(mysql_error($sql));
	Msg('','');
	break;
case 'modify';
	$sql="update ".$language."_keys set k_order=$k_order,k_name='$k_name',k_url='$k_url' where k_id=$id";
	mysql_query($sql) or die(mysql_error($sql));
	Msg('','');
	break;
case 'delete';
	$sql='delete from '.$language.'_keys where k_id='.$id;
	mysql_query($sql) or die(mysql_error($sql));
	Msg('','');
	break;
}
?>
<div id="container">
	<?php
	if ($meter==1){
	$query=mysql_query('select * from '.$language.'_keys where k_id='.$id);
	$row=mysql_fetch_array($query);
	?>
    <div class="edit">
      <h1>޸热门搜索<a href="javascript:location.reload();">刷新</a></h1>
      <form name="form1" method="post" action="?act=modify&id=<?php echo $id ?>" onsubmit="return CheckAd(this);">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="edit_title">关 键 词：</td>
            <td><input name="k_name" type="text" class="inputtext" value="<?php echo $row['k_name']?>" size="30" maxlength="50" /></td>
          </tr>
          <tr>
            <td class="edit_title">排　　序：</td>
            <td><input name="k_order" type="text" class="inputtext" value="<?php echo $row['k_order']?>" size="30" maxlength="10" /></td>
          </tr>
		  <tr>
            <td class="edit_title">链接地址：</td>
            <td><input name="k_url" type="text" class="inputtext" value="<?php echo $row['k_url']?>" size="100" maxlength="255" /></td>
          </tr>
          <tr>
            <td height="30">&nbsp;</td>
			<td><input name="button" type="submit" value=" 修改 " class="button" />&nbsp;<input name="button" type="button" value=" 返回 " class="button" onclick="history.back();" /></td>
          </tr>
        </table>
      </form>
    </div>
	<?php
	}
	else{
	?>
	<div class="view">
		<h1>热门搜索<a href="javascript:location.reload();">刷新</a></h1>
	    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        	<tr class="v_title">
            	<td width="70%">关键词</td>
            	<td width="15%">排序</td>
				<td width="15%">操作</td>
        	</tr>
			<?php
			$col=1;
			$str='';
			$query=mysql_query('select * from '.$language.'_keys order by k_order,k_id');
			if (mysql_num_rows($query)>0){
				while($row=mysql_fetch_array($query)){
					$str.='<tr onmouseover="this.className=\'view_trover\';" onmouseout="this.className=\'view_trout\';">';
					$str.='<td>'.$row['k_name'].'&nbsp;</td>';
					$str.='<td style="padding:2px 0px;"><div class="inputorder" id="inputorder_'.$row['k_id'].'" contenteditable="true" onblur="Order(\'keys\','.$row['k_id'].')">'.$row['k_order'].'</div></td>';
					$str.='<td><a href="?meter=1&id='.$row['k_id'].'">修改</a> | <a href="?act=delete&id='.$row['k_id'].'" onclick="return ConfirmDel();">删除</a></td>';
					$str.='</tr>';
					$col++;
				}
			}
			echo $str;
			?>
		</table>
	</div><br />
    <div class="edit">
      <h1>&nbsp;</h1>
      <form name="form1" method="post" action="?act=add" onsubmit="return CheckKeys(this);">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="edit_title">关 键 词：</td>
            <td><input name="k_name" type="text" class="inputtext" size="30" maxlength="50" /></td>
          </tr>
          <tr>
            <td class="edit_title">排　　序：</td>
            <td><input name="k_order" type="text" class="inputtext" value="<?php echo $col ?>" size="30" maxlength="10" /></td>
          </tr>
		  <tr>
            <td class="edit_title">链接地址：</td>
            <td><input name="k_url" type="text" class="inputtext" size="100" maxlength="255" /></td>
          </tr>
          <tr>
            <td height="30">&nbsp;</td>
			<td><input name="button" type="submit" value=" 添加 " class="button" /></td>
          </tr>
        </table>
      </form>
    </div>
    <?php } ?>
</div>
</body>
</html>